#!/usr/bin/env python
# encoding: utf-8
"""
@summary: 车型访问情况；reducer计算
@author: hongxingfan
@since: 2014年8月7日    下午3:48:01
"""
import sys


def trimIdToModelId():
    trimIdToModelId = {}
    
    try:
        f = open("trimIdToModelId.txt", "r")
        for line in f.readlines():
            line = line.strip()
            cols = line.split("\t")
            trimIdToModelId[cols[0]] = cols[1]
    except:
        print("read trimIdToModelId.txt has error!")
        sys.exit(0)
    return trimIdToModelId

if __name__ == "__main__":
    
    hash_result = {}
    trimIdToModelId = trimIdToModelId()
    
    for line in sys.stdin:
        line = line.strip()
        cols = line.split("\t")
        
        type = cols[0]
        typeId = cols[1]
        # 将trim转化成model
        if "trim" == type:
            typeId = trimIdToModelId.get(typeId, typeId)
        key = typeId
        pv = int(cols[2])
        suv = cols[3]
        
        if key in hash_result:
            value = hash_result.get(key)
            value[0] += pv
            value[1].add(suv)
        else:
            hash_result[key] = [pv, set([suv])]
    
    # 最终结果输出
    for (k, v) in hash_result.items():
        print("%s\t%s\t%s" % (k, v[0], len(v[1])))    
